//
//  XKTradeHeaderView.m
//  XKJY
//
//  Created by xuyaguang on 2017/1/10.
//  Copyright © 2017年 xiaokang100. All rights reserved.
//

#import "XKHomeHeaderView.h"

@interface XKHomeHeaderView () <SDCycleScrollViewDelegate>
@property (nonatomic, strong) UIImageView *topImageView;
@property (nonatomic, strong) UIView *bgView;
@property (nonatomic, strong) UILabel *titleLabel;
@property (nonatomic, strong) UILabel *timeLabel;
@property (nonatomic, strong) UILabel *priceLabel;
@property (nonatomic, strong) UIImageView *arrowImageView;

@end
@implementation XKHomeHeaderView

#pragma mark - 重写构造方法
- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self configArguments];
        [self createSubviews];
        [self addConstraints];
    }
    return self;
}

#pragma mark - 设置自身
- (void)configArguments {
    self.backgroundColor = kBaseGrayColor;
    
}

#pragma mark - 创建控件
- (void)createSubviews {
    
    UIImageView *topImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"banner_01"]];
    _topImageView = topImageView;
    topImageView.userInteractionEnabled = YES;
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(topImageViewTapEvent:)];
    [topImageView addGestureRecognizer:tap];
    
    
    _bgView = [UIView new];
    _bgView.backgroundColor = WhiteColor;
    _bgView.layer.cornerRadius = 10*Scale_W;
    _bgView.layer.masksToBounds = YES;
    
    _titleLabel = [UILabel getLabWithText:@"小康种子WOS" textFont:18*Scale_W textColor:kBaseRedColor];
    _timeLabel = [UILabel getLabWithText:@"更新时间: 2017-01-01 00:00" textFont:Font_10 textColor:UIColorFromRGB(0xFF7676)];
    _priceLabel = [UILabel getLabWithText:@"¥0.00" textFont:40*Scale_W textColor:kBaseRedColor textAlignment:NSTextAlignmentRight];
    _priceLabel.layer.transform = CATransform3DMakeScale(0.9, 1.0, 1.0);
    [_priceLabel setColumnSpace:5];
    
    _arrowImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"index_head_icon_up"]];
}
#pragma mark - 添加约束
- (void)addConstraints {
    
    [self addSubview:self.topImageView];
    [self.topImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.top.right.mas_equalTo(self);
        make.height.mas_equalTo(180*Scale_H);
    }];
    
    [self addSubview:self.bgView];
    [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.topImageView.mas_bottom).offset(5*Scale_H);
        make.left.mas_equalTo(10*Scale_W);
        make.right.mas_equalTo(-10*Scale_W);
        make.height.mas_equalTo(67*Scale_H);
    }];
    
    [self.bgView addSubview:self.titleLabel];
    [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.bgView).offset(15*Scale_W);
        make.top.mas_equalTo(self.bgView).offset(15*Scale_H);
    }];
    
    [self.bgView addSubview:self.timeLabel];
    [_timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.titleLabel);
        make.bottom.mas_equalTo(self.bgView).offset(-15*Scale_H);
    }];
    
    [self.bgView addSubview:self.arrowImageView];
    [_arrowImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(self.bgView).offset(-17*Scale_W);
        make.centerY.mas_equalTo(self.bgView);
        make.size.mas_equalTo(CGSizeMake(15*Scale_W, 35*Scale_H));
    }];
    
    [self addSubview:self.priceLabel];
    [_priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(self.arrowImageView.mas_left).offset(0*Scale_W);
        make.centerY.mas_equalTo(self.bgView);
    }];
    
}

- (void)topImageViewTapEvent:(UITapGestureRecognizer *)tap {
    if ([self.delegate respondsToSelector:@selector(pushToOfficialWebsite)]) {
        [self.delegate pushToOfficialWebsite];
    }
}


- (void)setCurrentPriceString:(NSString *)currentPriceString {
    _currentPriceString = currentPriceString;    
    self.priceLabel.text = [NSString stringWithFormat:@"¥%@",currentPriceString];
}

- (void)setRefreshTimeString:(NSString *)refreshTimeString {
    _currentPriceString = refreshTimeString;
    self.timeLabel.text = [NSString stringWithFormat:@"更新时间: %@",refreshTimeString];
}

- (void)setWosPriceStatus:(NSString *)wosPriceStatus {
    if ([wosPriceStatus isEqualToString:@"0"]) {
        self.arrowImageView.image = [UIImage imageNamed:@"index_head_icon_down"];
    } else {
        self.arrowImageView.image = [UIImage imageNamed:@"index_head_icon_up"];
    }
}

@end
